import { Controller, UseGuards, Body, Post, Req, Query, Get } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiUseTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';

import { RequestUser } from '@/common/interfaces/request.interface';
import { ApiResult } from '@/common/interceptors/result.interceptor';

import { InterfaceService } from './interface.service';
import { InterfaceDto } from './dto/interface.dto';
import { SearchInterfaceDto } from './dto/search-interface.dto';

@ApiUseTags('接口模版')
@ApiBearerAuth()
@Controller('interface')
@UseGuards(AuthGuard())
export class InterfaceController {

  constructor(private interfaceService: InterfaceService) { }

  @Post('demand/add')
  @ApiOperation({
    title: '需求模块 添加接口',
    description: '需求模块,新增接口弹出框，保存接口'
  })
  async addDemandInterface(@Req() req: RequestUser, @Body() param: InterfaceDto) {
    const data = Object.assign(param, { userId: req.user._id })
    await this.interfaceService.addDemandInterface(data);
    return new ApiResult('');
  }

  @Post('demand/list')
  @ApiOperation({
    title: '需求模块 查询接口列表',
    description: '需求模块,查询接口列表'
  })
  async searchInterfaceList( @Body() searchDto: SearchInterfaceDto) {
    const data = await this.interfaceService.searchDemandInterfaceList(searchDto);
    return new ApiResult(data);
  }
}
